package controllers;


import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import model.Employee;
import model.Envelope;
import model.User;
import view.AnalyzeGui;
import view.AreaGui;
import view.CampaignPaternGUI;
import view.InsertPotentialGui;
import view.MarketingGui;
import view.NewItemGUI;
/**
 * This Class is a Marketing Controller, which extends AbstractTransfer
 * @author jacob
 *
 */
public class MarketingController extends AbstractTransfer {

    Employee MarMod;	
	MarketingGui MarkGui;
	MarketingController tempCon;
	LoginController prevController;
	
	public MarketingController(){ 
	}
	/**
	 * Constructor function
	 * @param MC is Employee instance
	 * @param MG is MarketingGui instance
	 * @param lastCon is LoginController instance which is previous Controller
	 */
  public MarketingController(Employee MC, MarketingGui MG,LoginController lastCon){
	  super(MG,MC);
	  tempCon = this;
	  MarkGui =  MG;
	  MarMod = MC;
	  prevController = lastCon;
	  //action listener 
	  MarkGui.addLogoutActionListener(new LogOutListener() );
	  MarkGui.addcreateNewMarketingPatternActionListener(new CreateNewMarkListener());
	  MarkGui.addAnalyzeActionListener(new AnylyzeListener());
	  MarkGui.addInsertFromDBActionListener(new InsertFromDBListener());
	  MarkGui.addNewProductActionListener(new NewProductListener());
	  
	}
  /**
   * Inner class that handles when Button logout Pressed, implements ActiontListener
   * @author jacob
   *
   */
 class LogOutListener implements ActionListener{

	@Override
	public void actionPerformed(ActionEvent e) {
		// TODO Auto-generated method stub
		UpdateDB(); //update the user to status 0 = logout
		MarkGui.dispose();
		prevController.getLoginG().ClearText();
		prevController.getLoginG().setVisible(true);
		
	}
	  
 }
 
 /**
  * Inner class that handles when Button create new marketing pattern Pressed, implements ActiontListener
  * @author jacob
  *
  */
 class CreateNewMarkListener implements ActionListener{

	@Override
	public void actionPerformed(ActionEvent e) {
		// TODO Auto-generated method stub
		MarkGui.dispose();
		CampaignPaternGUI CampaignPaternGUI =  new CampaignPaternGUI();
		CampaignPaternController  CampaignPaternController  = new CampaignPaternController(CampaignPaternGUI,tempCon);
	}
	  
 }
 /**
  * Inner class that handles when Button New Product Pressed, implements ActiontListener
  * @author jacob
  *
  */
 class NewProductListener implements ActionListener{

	@Override
	public void actionPerformed(ActionEvent e) {
		// TODO Auto-generated method stub	
		MarkGui.dispose();
		NewItemGUI NewItemGUI =  new NewItemGUI();
		NewItemController  NewItemcon  = new NewItemController(NewItemGUI,tempCon);
	}	  
 }
 /**
  *  Inner class that handles when Analyze Pressed, implements ActiontListener
  * @author jacob
  *
  */
 class AnylyzeListener implements ActionListener{

	@Override
	public void actionPerformed(ActionEvent e) {
		// TODO Auto-generated method stub
		MarkGui.dispose();
		AnalyzeGui AnaGui = new AnalyzeGui();
		AnalyzeController anacon = new AnalyzeController(tempCon, AnaGui);
				
	}	  
 }
 /**
  *  Inner class that handles when Insert Potential customer Pressed, implements ActiontListener
  * @author jacob
  *
  */
 class InsertFromDBListener implements ActionListener{

	@Override
	public void actionPerformed(ActionEvent e) {
		// TODO Auto-generated method stub
		MarkGui.dispose();
		InsertPotentialGui InsertPoView = new InsertPotentialGui();
		InsertPostentialController InsertPoCont = new InsertPostentialController(InsertPoView,tempCon);
		
	}
	  
 }
 /**
  *  get the previous Controller
  * @return LoginController
  */
public LoginController getPrevController() {
	return prevController;
}
/**
 * set the previous Controller
 * @param prevController
 */
public void setPrevController(LoginController prevController) {
	this.prevController = prevController;
}
/**
 * get the Employee instance
 * @return Employee
 */
public Employee getMarMod() {
	return MarMod;
}
/**
 * get the Marketing Gui instance
 * @return MarketingGui
 */
public MarketingGui getMarkGui() {
	return MarkGui;
}
 /**
  *  UpdateDB function
  */
public void UpdateDB(){
	//update the status of  current  user to 0 - logoff
	 Envelope en1 = new Envelope(MarMod,"updateStatus0");
	 sendToServer(en1);
} 
  
  
  
}
